package com.ydd.controller.admin;

import com.ydd.dto.AdvposPageQueryDTO;
import com.ydd.entity.YddAdvpos;
import com.ydd.result.PageResult;
import com.ydd.result.Result;
import com.ydd.service.YddAdvposService;
import com.ydd.vo.AdvposVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description TODO
 * @Author fang
 * @Date 2023-05-29 16:47
 */
@Api(tags = "广告管理-广告位管理")
@RestController
@RequestMapping("/admin/ydd_advpos")
@Slf4j
public class YddAdvposController {
    @Autowired
    YddAdvposService yddAdvposService;

    /**
     * GET 广告位列表-分页
     *
     * @param advposPageQueryDTO
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("广告位分页查询")
    public Result<PageResult> page(AdvposPageQueryDTO advposPageQueryDTO) {
        log.info("广告位分页查询：{}", advposPageQueryDTO);

        //调用业务层方法，封装成pageResult数据返回
        PageResult pageResult = yddAdvposService.page(advposPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 广告位全部查询
     *
     * @return
     */
    @GetMapping("/all")
    @ApiOperation("广告位全部查询")
    public Result selectAll() {
        List<YddAdvpos> list = yddAdvposService.all();
        return Result.success(list);
    }

    /**
     * 根据ID查询广告位详情
     *
     * @param id
     * @return
     */
    @GetMapping("/rowInfo")
    @ApiOperation("根据ID查询广告位详情")
    public Result selectById(String id) {
        YddAdvpos yddAdvpos = yddAdvposService.selectById(id);
        return Result.success(yddAdvpos);
    }

    /**
     * 广告位修改
     *
     * @param yddAdvpos
     * @return
     */
    @PostMapping("/update")
    @ApiOperation("广告位修改")
    public Result update(@RequestBody YddAdvpos yddAdvpos) {
        yddAdvposService.update(yddAdvpos);
        return Result.success();
    }

    /**
     * 广告位添加
     * @param yddAdvpos
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("广告位添加")
    public Result add(@RequestBody YddAdvpos yddAdvpos) {

        yddAdvposService.add(yddAdvpos);
        return Result.success();
    }


    @GetMapping("/del")
    @ApiOperation("广告位删除")
    public Result delete(String id){
        yddAdvposService.delete(id);
        return Result.success();
    }
}
